var webButton;
var identityButton;
var photographyButton;
var motionButton;
var allProjects;
var currentIndex = -1;


window.onload = function() {
    webButton = $('#web_div');
    webButton.mouseenter(selectMenuItem);
  
    identityButton = $('#identity_div');
    identityButton.mouseenter(selectMenuItem);
    
    photographyButton = $('#photography_div');
    photographyButton.mouseenter(selectMenuItem);
    
    motionButton = $('#motion_div');
    motionButton.mouseenter(selectMenuItem);
    
    $('.last_works_img').click(jumpToSlide);
    
    $('#facebook_div').hover(selectMenuItem, notSelectMenuItem);

    $.post(
    		"/projectSlideShow",
    		{},
    		loadProjectsSlideShow,
    		"json");  
    
}

function jumpToSlide(){
	var blobKey = $(this).attr('src').substring(30);
	var button = $(this);
	if($(this).attr('alt') === ''){
		$.each( allProjects, function(i){
			if(this.blobKey === blobKey){
				button.attr('alt',i + 1);
			}
		});		
	}
}

function loadProjectsSlideShow(data) {
	allProjects = data;
	for(var index = 0; index < allProjects.length; index++) {
		$('<div class="simpleSlide-slide hiden slide_pics" rel="1" alt="' + (index + 1) + '"><img id="slide_content_img slide_pics" src="/projectSlideShow?blobKey=' + allProjects[index].blobKey + '"/></div>').appendTo('#slide_navi');
	}
	refreshSlideShow();
}

function refreshSlideShow() {
    simpleSlide({
    	'set_speed': 500,
    	'status_width': 60,
    	'status_color_outside': '#aaa',
    	'status_color_inside': '#fff',
    	'fullscreen': 'false',
    	'swipe': 'true',
    	'callback': function() {
    	}
    });
}

function selectMenuItem(){
	
	if(webButton.hasClass('web_btn_selected')){
    	 webButton.removeClass('web_btn_selected');
     }
	if(identityButton.hasClass('identity_btn_selected')){
		identityButton.removeClass('identity_btn_selected');
		
	}
	if(photographyButton.hasClass('photo_btn_selected')){
		photographyButton.removeClass('photo_btn_selected');
	}
	
	if(motionButton.hasClass('motion_btn_selected')){
		motionButton.removeClass('motion_btn_selected');
	}

	if($(this).attr('id') === 'web_div'){
		webButton.addClass('web_btn_selected');
	}else if($(this).attr('id') === 'identity_div'){
		identityButton.addClass('identity_btn_selected');
     }else if($(this).attr('id') === 'photography_div'){
		photographyButton.addClass('photo_btn_selected');
	}else if($(this).attr('id') === 'motion_div'){
		motionButton.addClass('motion_btn_selected');
     }
	
    
}
function notSelectMenuItem(){
    $(this).removeClass('selected_menu_item');
}